enum HttpMethod { GET, POST, DELETE }

// 基础请求
abstract class BaseRequest {
  var pathParams; // 路径参数
  var useHttps=false; // 是否采用Https
  String authority() {
    return "127.0.0.1:8003";
  }
  HttpMethod httpMethod(); // 获取请求方式
  String path(); // 获取请求路径
  // 获取请求url
  String url() {
    Uri uri;
    var pathStr = path();
    // 拼接path参数
    if (pathParams!=null){
      if (path().endsWith("/")) {
        pathStr = "${path()}$pathParams";
      } else {
        pathStr = "${path()}/$pathParams";
      }
    }
    // http和https的切换
    if (useHttps) {
      uri = Uri.https(authority(), pathStr, params);
    } else{
      uri = Uri.http(authority(), pathStr, params);
    }
    print('url:${uri.toString()}');
    return uri.toString();
  }
  // 这个接口是否需要登录
  bool needLogin();

  // Form参数
  Map<String, String> params = Map();
  // 添加参数
  BaseRequest addParams(String k, Object v) {
    params[k] = v.toString();
    return this;
  }

  Map<String, dynamic> header = Map();
  BaseRequest addHeader(String k, Object v) {
    header[k] = v.toString();
    return this;
  }
}
